<template>
    <div style="height:100%;width:100%;position:relative;">
        <div class="pagetop">
            <div class="top-title">快速查询</div>
            <el-input v-model="txtsearch" placeholder="药物组合代码|名称|输入码" @keyup.enter.native="filterQuery" style="width:240px"></el-input>
            <div class="top-button">
                <el-button @click="btnQuery" icon="el-icon-search" type="primary" v-has="'PINQUERY'" :disabled="bChangeFlag">查询</el-button>
                <el-button @click="btnAdd" icon="el-icon-plus" v-has="'PADD'" :disabled="bChangeFlag">新增</el-button>
                <el-button @click="btnDel" icon="el-icon-delete" v-has="'PDELETE'" :disabled="bChangeFlag">删除</el-button>
                <el-button @click="btnSave" icon="el-icon-document" v-has="'PMODIFY'" :disabled="!bChangeFlag">保存</el-button>
                <el-button @click="btnClear" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
                <el-button @click="btnExport" icon="el-icon-upload2" :disabled="bChangeFlag">导出</el-button>
            </div>
        </div>
        <div class="pagecenter">
            <rm-layout-right splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="600" min-width="570">
                <div style="height:100%">
                    <vxe-table :data.sync="showLXTableData" :loading="bLoading" :keyboard-local-config="keyLocalConfig" :row-class-name="lRowClassName" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
            trigger: 'click',
            mode: 'cell',
            showStatus: true,
            showIcon: false,
          }" @current-change="CurrentChangeEvent" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="lXTable" resizable size="mini" stripe show-header-overflow="tooltip" show-overflow="tooltip" headalign="center" align="center">
                        <vxe-table-column field="collectdictname" title="采样时间字典名称" width="120"></vxe-table-column>
                        <vxe-table-column field="note" title="说明" width="160"></vxe-table-column>
                        <vxe-table-column field="hospcode" title="所属医院" width="160" :formatter="formatFun"></vxe-table-column>
                        <vxe-table-column title="采血时间">
                            <vxe-table-column field="weekday1" title="周一" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday2" title="周二" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday3" title="周三" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday4" title="周四" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday5" title="周五" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday6" title="周六" width="80" :formatter="formatFun"></vxe-table-column>
                            <vxe-table-column field="weekday7" title="周日" width="80" :formatter="formatFun"></vxe-table-column>
                        </vxe-table-column>
                        <vxe-table-column field="create_user" title="创建人" width="60" :formatter="formatFun"></vxe-table-column>
                        <vxe-table-column field="create_dt" title="创建时间" width="150"></vxe-table-column>
                        <vxe-table-column field="collectdictid" title="采样时间字典ID" width="120"></vxe-table-column>

                    </vxe-table>
                </div>
                <template v-slot:fix>
                    <div v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="height:100%">
                        <rm-layout-top splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="400" :canDrag="false">
                            <template v-slot:fix>
                                <div style="height:400px;border:1px solid #CCC">
                                    <el-form :label-position="labelPosition" label-width="80px" :model="masterData">
                                        <table class="table1style" style="width:100%;font-size:12px">
                                            <tr>
                                                <td align="right">采样时间字典ID</td>
                                                <td>
                                                    <el-input v-model="masterData.collectdictid" @input="HasChange" :readonly="actionindex == 'M'" @change="ChkKeyId" width="100%" :disabled="true"></el-input>
                                                </td>
                                                <td align="right">创建人</td>
                                                <td>
                                                    <rm-ddl-common datatype="userinfo" dataname="用户" v-model="masterData.create_user" width="100%" :disabled="true" min-width="190px"></rm-ddl-common>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right" style="color:#F56C6C">采样时间字典名称</td>
                                                <td>
                                                    <el-input v-model="masterData.collectdictname" @input="HasChange" ref="input0" @keyup.enter.native="NextFocus(0)" style="width:100%"></el-input>
                                                </td>
                                                <td align="right">创建时间</td>
                                                <td>
                                                    <el-input v-model="masterData.create_dt" :disabled="true" style="width:100%;" min-width="190px"></el-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right" style="color:#F56C6C">所属医院</td>
                                                <td>
                                                    <rm-ddl-common datatype="hospital" dataname="医院" v-model="masterData.hospcode" @change="HasChange" width="100%"></rm-ddl-common>
                                                </td>
                                                <td align="right">说明</td>
                                                <td>
                                                    <el-input ref="input1" @keyup.enter.native="NextFocus(1)" v-model="masterData.note" @input="HasChange" style="width:100%"></el-input>
                                                </td>
                                            <tr>
                                                <td align="right" style="font-size:blod">采血时间</td>
                                                <td colspan="3"></td>
                                            </tr>
                                            <tr>
                                                <td align="right">周一</td>
                                                <td>
                                                    <el-radio-group v-model="wd[0]" @change="getWeekDayTime(1)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input2" @keyup.enter.native="NextFocus(2)">全天采样</el-radio-button>
                                                        <!-- @keyup.right.native="$refs.input2c.$el.focus()" -->
                                                        <el-radio-button ref="input2c" label="0" @keyup.enter.native="NextFocus(2)">禁止采样</el-radio-button>
                                                        <!-- @keyup.left.native="$refs.input2.$el.focus()" @keyup.right.native="$refs.input2r.$el.focus()" -->
                                                        <el-radio-button ref="input2r" label="3" @keyup.enter.native="NextFocus(2)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input21" v-if="wd[0]=='3'" type="text" class="data-control" v-model="masterData.weekday1" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(2)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周二</td>
                                                <td>
                                                    <el-radio-group v-model="wd[1]" @change="getWeekDayTime(2)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input3" @keyup.enter.native="NextFocus(3)">全天采样</el-radio-button>
                                                        <!-- @keyup.right.native="$refs.input3c.$el.focus()" -->
                                                        <el-radio-button ref="input3c" label="0" @keyup.enter.native="NextFocus(3)">禁止采样</el-radio-button>
                                                        <!-- @keyup.left.native="$refs.input3.$el.focus()" @keyup.right.native="$refs.input3r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input3r" @keyup.enter.native="NextFocus(3)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input32" v-if="wd[1]=='3'" type="text" class="data-control" v-model="masterData.weekday2" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(3)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周三</td>
                                                <td>
                                                    <el-radio-group v-model="wd[2]" @change="getWeekDayTime(3)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input4" @keyup.enter.native="NextFocus(4)">全天采样</el-radio-button>
                                                        <!--  @keyup.right.native="$refs.input4c.$el.focus()" -->
                                                        <el-radio-button ref="input4c" label="0" @keyup.enter.native="NextFocus(4)">禁止采样</el-radio-button>
                                                        <!--  @keyup.left.native="$refs.input4.$el.focus()" @keyup.right.native="$refs.input4r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input4r" @keyup.enter.native="NextFocus(4)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input43" v-if="wd[2]=='3'" type="text" class="data-control" v-model="masterData.weekday3" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(4)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周四</td>
                                                <td>
                                                    <el-radio-group v-model="wd[3]" @change="getWeekDayTime(4)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input5" @keyup.enter.native="NextFocus(5)">全天采样</el-radio-button>
                                                        <!--  @keyup.right.native="$refs.input5c.$el.focus()" -->
                                                        <el-radio-button ref="input5c" label="0" @keyup.enter.native="NextFocus(5)">禁止采样</el-radio-button>
                                                        <!--  @keyup.left.native="$refs.input5.$el.focus()" @keyup.right.native="$refs.input5r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input5r" @keyup.enter.native="NextFocus(5)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input54" v-if="wd[3]=='3'" type="text" class="data-control" v-model="masterData.weekday4" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(5)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周五</td>
                                                <td>
                                                    <el-radio-group v-model="wd[4]" @change="getWeekDayTime(5)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input6" @keyup.enter.native="NextFocus(6)">全天采样</el-radio-button>
                                                        <!--  @keyup.right.native="$refs.input6c.$el.focus()" -->
                                                        <el-radio-button ref="input6c" label="0" @keyup.enter.native="NextFocus(6)">禁止采样</el-radio-button>
                                                        <!--  @keyup.left.native="$refs.input6.$el.focus()" @keyup.right.native="$refs.input6r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input6r" @keyup.enter.native="NextFocus(6)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input65" v-if="wd[4]=='3'" type="text" class="data-control" v-model="masterData.weekday5" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(6)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周六</td>
                                                <td>
                                                    <el-radio-group v-model="wd[5]" @change="getWeekDayTime(6)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input7" @keyup.enter.native="NextFocus(7)">全天采样</el-radio-button>
                                                        <!--  @keyup.right.native="$refs.input7c.$el.focus()" -->
                                                        <el-radio-button ref="input7c" label="0" @keyup.enter.native="NextFocus(7)">禁止采样</el-radio-button>
                                                        <!--  @keyup.left.native="$refs.input7.$el.focus()" @keyup.right.native="$refs.input7r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input7r" @keyup.enter.native="NextFocus(7)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input76" v-if="wd[5]=='3'" type="text" class="data-control" v-model="masterData.weekday6" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(7)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right">周日</td>
                                                <td>
                                                    <el-radio-group v-model="wd[6]" @change="getWeekDayTime(7)" width="100%" min-width="210px">
                                                        <el-radio-button label="1" ref="input8" @keyup.enter.native="NextFocus(8)">全天采样</el-radio-button>
                                                        <!--  @keyup.right.native="$refs.input8c.$el.focus()" -->
                                                        <el-radio-button ref="input8c" label="0" @keyup.enter.native="NextFocus(8)">禁止采样</el-radio-button>
                                                        <!--  @keyup.left.native="$refs.input7.$el.focus()" @keyup.right.native="$refs.input7r.$el.focus()" -->
                                                        <el-radio-button label="3" ref="input8r" @keyup.enter.native="NextFocus(8)">自定义</el-radio-button>
                                                    </el-radio-group>
                                                </td>
                                                <td colspan="2">
                                                    <masked-input ref="input87" v-if="wd[6]=='3'" type="text" class="data-control" v-model="masterData.weekday7" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%" @keyup.enter.native="NextFocus(8)" min-width="240px" @change="HasChange"></masked-input>
                                                </td>
                                            </tr>
                                        </table>
                                    </el-form>
                                </div>
                            </template>
                            <div style="height:100% ;width:100%;background-color:#ddccbb;" class="detailxTable">
                                <vxe-table :data="rXTableData" :loading="bLoading" :keyboard-config="selKeyConfig" :keyboard-local-config="selKeyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
                trigger: 'click',
                mode: 'cell',
                showStatus: true,
                activeMethod: ActiveMethod,
                showIcon: false,
              }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="rXTable" resizable size="mini" stripe :row-class-name="rRowClassName" :cell-class-name="rCellClassName" :mouse-config="{selected: true}" show-header-overflow="tooltip" show-overflow="tooltip">
                                    <vxe-table-column field="holidaydt" title="特定日期" width="110" :formatter="['toDateString', 'yyyy/MM/dd']" sortable>
                                        <template width="100" v-slot="{row}">
                                            <div class="block; padding:0px 0px 0px 0px">
                                                <el-date-picker v-model="row.holidaydt" align="right" type="date" style="middle-center" @change="HasChange">
                                                </el-date-picker>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column title="采样时间" width="230" :formatter="['toDateString', 'yyyy/MM/dd']" sortable header-align="right">
                                        <template width="100" v-slot="{row}">
                                            <div class="block; padding:0px 0px 0px 0px">
                                                <el-radio-group v-model="row.rowWd" @change="getWeekDayTime(8,row)" width="100%" min-width="210px">
                                                    <el-radio-button label="1" ref="input2">全天采样</el-radio-button>
                                                    <!-- @keyup.right.native="$refs.input2c.$el.focus()" -->
                                                    <el-radio-button ref="input2c" label="0">禁止采样</el-radio-button>
                                                    <!-- @keyup.left.native="$refs.input2.$el.focus()" @keyup.right.native="$refs.input2r.$el.focus()" -->
                                                    <el-radio-button ref="input2r" label="3">自定义</el-radio-button>
                                                </el-radio-group>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="collecttime" title="" width="260" sortable>
                                        <template width="100" v-slot="{row}">
                                            <div class="block; padding:0px 0px 0px 0px">
                                                <masked-input v-if="row.rowWd=='3'" type="text" class="data-control" v-model="row.collecttime" :mask="maskFunc" :guide="false" placeholderChar="#" witdh="90%"></masked-input>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <!-- <vxe-table-column field="collecttime" title="" width="200" align="center"> -->
                                    </vxe-table-column>
                                    <template v-slot:fix>
                                        <div style="font-size:17px;padding:3px;background-color:#fff;text-align:center;font-weight:bold">
                                            <el-button @click="btnDetailAdd()" class="el-button--310">新增明细</el-button>
                                            <el-button @click="btnDetailDel()" class="el-button--310">删除明细</el-button>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                        </rm-layout-top>
                    </div>
                </template>
            </rm-layout-right>
        </div>
    </div>
</template>

<script type="text/javascript">
import XE from "xe-utils";
export default {
    name: "MNG237",
    data() {
        return {
            txtsearch: "",
            actionindex: "M",
            labelPosition: "right",
            bLoading: false,
            bChangeFlag: false,
            bPopLabMed: false,
            bPageInitLoading: false,
            selKeyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
            },
            selKeyLocalConfig: {
                isArrow: true,
            },
            keyLocalConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true,
            },
            //主表数据初始化
            masterData: {
                collectdictid: -1, //采样时间字典ID
                hospcode: "", //医院代码
                collectdictname: 0, //采样时间字典名称
                note: "", //说明
                create_user: "", //创建人
                create_dt: "", //创建时间
                //采血时间
                weekday1: "", //周一
                weekday1: "", //周二
                weekday1: "", //周三
                weekday1: "", //周四
                weekday1: "", //周五
                weekday1: "", //周六
                weekday1: "", //周日
            },
            wd: ["1", "1", "1", "1", "1", "1", "1"], //radio默认勾选 全天采样
            showWeekday: ["08:00-16:00", "08:00-16:00", "08:00-16:00", "08:00-16:00", "08:00-16:00", "08:00-16:00", "08:00-16:00"], //显示的采样时间
            selectConfig: { tigger: "row" },
            labMedRow: {},
            tempmed: {},
            tmpMasterlData: {},
            selrow: [],
            AddData: [], //新增数据 用于变色
            ModData: [], //修改数据 用于变色
            lXTableData: [],
            rXTableData: [],
            showLXTableData: [],
            hospOption: [], //医院              后台查询获取
            userOption: [], //用户
        };
    },
    created() {
        this.initOption();
    },
    methods: {
        //----------------- 查询类 ----------------- //
        //主表查询
        filterQuery() {
            let filterName = this.txtsearch.trim();
            if (filterName) {
                let rest = this.lXTableData.filter((item) => {
                    return item.collectdictid.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.inputcode ? item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.medgroupname ? item.medgroupname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
                });
                this.showLXTableData = rest;
            } else {
                this.showLXTableData = this.lXTableData;
            }
            let row = this.showLXTableData[0];
            if (row) {
                this.HightLightRow(row);
            } else {
                this.HightLightRow(false);
            }
        },
        btnQuery() {
            this.AddData = [];
            this.ModData = [];
            this.bLoading = true;
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG237",
                    method: "post",
                    data: {
                        action: "query",
                    },
                })
                .then((res) => {
                    this.lXTableData = res.data;
                    // this.showLXTableData=XE.clone(this.lXTableData,true)
                    this.filterQuery();
                    if (this.lXTableData.length == 0) this.actionindex = "A";
                    // this.HightLightRow(this.showLXTableData[0]);
                    this.bLoading = false;
                })
                .catch((e) => {
                    this.ErrorCatch(e, "", "error");
                    this.bLoading = false;
                });
        },
        //明细查询 -- 主表，子表
        async detailQuery(collectdictid, row) {
            try {
                this.selrow = row;
                this.actionindex = "M";
                this.bPageInitLoading = true;
                const res = await this.$tool.request({
                    url: "MNG/MNG2/MNG237",
                    method: "post",
                    data: {
                        action: "detailquery",
                        collectdictid: collectdictid,
                    },
                });
                if (res.reqcollectdict.length > 0) {
                    var tempData = res.reqcollectdict[0];
                    for (var i = 0; i < 7; i++) {
                        //mask采样时间 获取radio及显示的采样时间
                        var a = i + 1;
                        if (tempData["weekday" + (i + 1)] == "1") {
                            this.wd[i] = "1";
                        } else if (tempData["weekday" + (i + 1)] == "0") {
                            this.wd[i] = "0";
                        } else {
                            this.wd[i] = "3";
                            tempData["weekday" + (i + 1)] = this.transType(tempData["weekday" + (i + 1)]);

                            // this.showWeekday[i] = tempData["weekday" + (i + 1)];
                        }
                    }
                    this.masterData = tempData;
                    var tempDetailData = res.reqcollectdict_holiday;
                    tempDetailData.forEach((e) => {
                        //实际采样时间
                        if (e.collecttime == "1") {
                            e.rowWd = "1";
                            e.collecttime = "1";
                        } else if (e.collecttime == "0") {
                            e.rowWd = "0";
                            e.collecttime = "0";
                        } else {
                            e.rowWd = "3";
                            e.collecttime = this.transType(e.collecttime);
                        }
                    });
                    this.rXTableData = tempDetailData;
                } else {
                    this.masterData = {};
                    this.rXTableData = [];
                }
                this.tmpMasterlData = XE.clone(this.masterData, true);
                this.bPageInitLoading = false;
            } catch (e) {
                this.ErrorCatch(e, "", "error");
                this.bPageInitLoading = false;
            }
        },
        //主键查询  是否重复
        ChkKeyId() {
            this.$tool
                .request({
                    url: "MNG/MNG2/MNG237",
                    method: "post",
                    data: {
                        action: "chkkeyid",
                        collectdictid: this.masterData.collectdictid,
                    },
                })
                .then((res) => {
                    if (res == "1") {
                        this.$alert("药物组合代码重复，请重新填写！");
                        this.$refs.input0.focus();
                    }
                })
                .catch((e) => {
                    this.ErrorCatch(e, "", "error");
                });
        },
        //----------------- 按钮类 -----------------//
        //新增
        btnAdd() {
            this.bChangeFlag = true;
            this.actionindex = "A";
            this.masterData = {};
            this.wd = ["1", "1", "1", "1", "1", "1", "1"];
            this.rXTableData = [];
            this.$refs.input0.focus();
        },
        btnDetailAdd() {
            this.$refs.rXTable.insertAt(
                {
                    rowWd: "1",
                    collectdictid: this.masterData.collectdictid,
                    collecttime: "08:00-16:00",
                },
                -1
            );
            this.bChangeFlag = true;
        },
        btnDetailDel() {
            // this.$refs.rXTable.remove(this.$refs.rXTable.getCurrentRow()),
            //                 this.bChangeFlag = true
            try {
                var delrow = this.$refs.rXTable.getCurrentRow();
                if (delrow) {
                    var alld = this.$refs.rXTable.tableData;
                    var rowindex = alld.indexOf(delrow);
                    this.$refs.rXTable.remove(delrow);
                    let havedata = this.$refs.rXTable.tableData;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.rXTable.setCurrentRow(selectrow);
                    } else {
                        this.$refs.rXTable.setCurrentRow(null);
                    }
                    this.bChangeFlag = true;
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        //删除 -- 弹窗提示
        btnDel() {
            var delrow = this.$refs.lXTable.getCurrentRow();
            this.$confirm('确定删除采样时间为<b style="color:red">' + delrow.collectdictname + "[" + delrow.collectdictid + "]" + "</b>的记录吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                dangerouslyUseHTMLString: true,
                type: "warning",
            })
                .then(() => {
                    this.actionindex = "D";
                    this.confirmDel();
                })
                .catch((e) => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        //删除 -- 确认删除
        async confirmDel() {
            try {
                var delrow = this.$refs.lXTable.getCurrentRow();
                if (delrow) {
                    var alld = this.$refs.lXTable.tableData;
                    var rowindex = alld.indexOf(delrow);
                    await this.btnSave().then(() => {
                        this.$refs.lXTable.remove(delrow);
                        this.lXTableData.splice(rowindex, 1);
                        let havedata = this.$refs.lXTable.tableData;
                        if (havedata.length > 0) {
                            if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                            let selectrow = havedata[rowindex];
                            this.HightLightRow(selectrow);
                        } else {
                            this.HightLightRow(false);
                        }
                    });
                }
            } catch (e) {
                this.ErrorCatch(e, "", "error");
            }
        },
        //取消 -- 取消操作，数据还原
        btnClear() {
            this.$confirm("您确定要取消这次改动吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.bChangeFlag = false;
                    this.detailQuery(this.selrow.collectdictid, row);
                })
                .catch((e) => {});
        },
        //保存 -- 保存新增，修改，删除主表: lab_medgroup 子表: lab_medgroupdetail 操作//
        async btnSave() {
            try {
                // if (!this.masterData.medgroupname) {
                //     this.$alert("请填写采样时间字典名称。");
                //     this.$refs.input0.focus();
                //     return false;
                // }
                var saveData = XE.clone(this.masterData, true);
                for (var i = 0; i < 7; i++) {
                    var k = i + 1;
                    if (this.wd[i] == "1") {
                        saveData["weekday" + k] = "1";
                    } else if (this.wd[i] == "0") {
                        saveData["weekday" + k] = "0";
                    } else {
                        var savewd = saveData["weekday" + k].replace(/[^0-9]/gi, "");
                        if (savewd.length != 8 && savewd.length != 16 && savewd.length != 24) {
                            var cnNum;
                            switch (i) {
                                case 0:
                                    cnNum = "一";
                                    break;
                                case 1:
                                    cnNum = "二";
                                    break;
                                case 2:
                                    cnNum = "三";
                                    break;
                                case 3:
                                    cnNum = "四";
                                    break;
                                case 4:
                                    cnNum = "五";
                                    break;
                                case 5:
                                    cnNum = "六";
                                    break;
                                case 6:
                                    cnNum = "日";
                                    break;
                            }
                            this.$alert("周" + cnNum + "采血时间设置有误。");

                            this.$refs["input" + (i + 2) + (i + 1)].$el.focus();

                            return false;
                        } else {
                            saveData["weekday" + k] = savewd;
                        }
                    }
                }
                // let data = this.$refs.rXTable.getTableData().fullData;
                var rec = XE.clone(this.$refs.rXTable.getRecordset(), true);
                if (rec.insertRecords.length > 0) {
                    rec.insertRecords.forEach((e) => {
                        e.collecttime = e.collecttime.replace(/[^0-9]/gi, "");
                    });
                }
                if (rec.updateRecords.length > 0) {
                    rec.updateRecords.forEach((e) => {
                        e.cdata.collecttime = e.cdata.collecttime.replace(/[^0-9]/gi, "");
                    });
                }
                const res = await this.$tool.request({
                    url: "MNG/MNG2/MNG237",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "save",
                        utype: this.actionindex,
                        oldinfo: this.tmpMasterlData,
                        newinfo: saveData,
                        reqcollectdict_holiday: rec,
                    },
                });
                if (res.errcode == "1") {
                    
                    this.$message.success("保存成功！");
                    this.bChangeFlag = false;
                    this.masterData = saveData;
                    if (this.actionindex == "A") {
                        this.masterData.collectdictid = res.collectdictid;
                        if (this.AddData.indexOf(this.masterData.collectdictid) == -1) this.AddData.push(this.masterData.collectdictid);

                        this.$refs.lXTable.insert(this.masterData).then(({ row }) => {
                            this.HightLightRow(row);
                            this.lXTableData.push(row);
                        });
                    } else if (this.actionindex == "M") {
                        if (this.ModData.indexOf(this.masterData.collectdictid) == -1) this.ModData.push(this.masterData.collectdictid);
                        await this.SetToTable(this.masterData).then((row) => {
                            this.HightLightRow(row);
                        });
                    } else {
                        this.actionindex = "M";
                    }
                } else {
                    this.ErrorCatch(res.errmsg, "保存失败:", "error");
                }
            } catch (e) {
                this.ErrorCatch(e, "", "error");
            }
        },
        //导出
        btnExport() {
            this.$refs.lXTable.exportCsv({
                filename: "MNG237 抗生素组",
            });
        },
        ErrorCatch(e, msg, type) {
            this.$alert(msg + e, "提示", {
                confirmButtonText: "确定",
                type: type ? type : "error",
            });
        },
        //--------------- 数据改变及其他功能 ---------------//
        //行改变事件
        async CurrentChangeEvent({ row }) {
            if (this.bChangeFlag) {
                this.$refs.lXTable.setCurrentRow(this.selrow);
                return false;
            } else {
                this.selrow = row;
                await this.detailQuery(row.collectdictid, row);
            }
        },
        //保存后不刷新左侧主表,前台赋值。
        SetToTable(obj) {
            return new Promise((s, f) => {
                this.selrow.collectdictid = obj.collectdictid;
                this.selrow.medgroupname = obj.medgroupname;
                this.selrow.inputcode = obj.inputcode;
                this.selrow.seq = obj.seq;
                this.selrow.appmethod = obj.appmethod;
                if (obj.groupkind == "1") {
                    this.selrow.groupkind = "补充药敏";
                } else if (obj.groupkind == "9") {
                    this.selrow.groupkind = "仪器转用";
                } else {
                    this.selrow.groupkind = obj.groupkind;
                }
                this.selrow.printbar = obj.printbar;
                this.selrow.panelno = obj.panelno;
                this.selrow.hospcode = obj.hospcode;
                this.selrow.note = obj.note;    
                for (let i = 1; i < 8; i++) {
                    this.selrow["weekday" + i] = obj["weekday" + i];
                }
                s(this.selrow);
                return;
            });
        },
        // 焦点跳转
        NextFocus(index) {
            var focusIndex = index + 1;
            var that = this;
            if (index < 8) {
                if ([1, 2, 3, 4, 5, 6, 7].includes(index)) {
                    //radio
                    that.$refs["input" + focusIndex].$el.focus();
                } else {
                    that.$refs["input" + focusIndex].focus();
                }
            } else {
                //表单最后一格 回车 跳转明细表
                this.$refs.rXTable.insertAt(
                    {
                        rowWd: "1",
                        collectdictid: this.masterData.collectdictid,
                        collecttime: "08:00-16:00",
                        // holidaydt: "",
                    },
                    -1
                ),
                    this.$refs.rXTable.setActiveRow(this.$refs.rXTable.getTableData().fullData[this.$refs.rXTable.getTableData().fullData.length - 1], "med");
                this.$refs.rXTable.scrollToRow(this.$refs.rXTable.getTableData().fullData[this.$refs.rXTable.getTableData().fullData.length - 1]);
                this.bChangeFlag = true;
            }
        },
        ActiveMethod({ row }) {
            return true;
        },
        //数据发生改变 -- 按钮禁用/可用切换
        HasChange() {
            this.bChangeFlag = true;
        },
        //获取 抗生素弹窗 行数据
        popGetRow(row) {
            this.tempmed = XE.clone(row.medcode);
            this.labMedRow = row;
            this.bPopLabMed = true;
        },
        //获取输入码
        // CreateInputcode() {
        //     this.masterData.inputcode = this.$pub.CreateInputcode(this.masterData.medgroupname, this, 16);
        // },
        //设置高亮选中行
        async HightLightRow(row) {
            if (!!row) {
                this.$refs.lXTable.setCurrentRow(row);
                this.selrow = row;
                await this.detailQuery(row.collectdictid, row);
            } else {
                this.$refs.lXTable.setCurrentRow(null);
                this.masterData = {};
                this.tmpMasterlData = {};
                this.rXTableData = [];
            }
        },
        //radio点击事件
        getWeekDayTime(num, row) {
            this.bChangeFlag = true;
            if (num < 8) {
                //masterData数据
                if (this.wd[num - 1] == "3") {
                    //自定义
                    this.masterData["weekday" + num] = "08:00-16:00";
                    // this.masterData["weekday" + (num + 1)] = "08001600";
                    this.$refs["input" + (num + 1) + num].$el.focus();
                }
            }
            if (row) {
                //rXTable数据
                if (row.rowWd == "1") {
                    row.collecttime = "1";
                } else if (row.rowWd == "0") {
                    row.collecttime = "0";
                } else if (row.rowWd == "3") {
                    row.collecttime = "08:00-16:00";
                }
            }
        },
        //mask正则 最多三列时间段，','隔开
        maskFunc(rawValue) {
            let rval = [/[0-2]/, /\d/, ":", /[0-5]/, /\d/, "-", /[0-2]/, /\d/, ":", /[0-5]/, /\d/, ",", /[0-2]/, /\d/, ":", /[0-5]/, /\d/, "-", /[0-2]/, /\d/, ":", /[0-5]/, /\d/, ",", /[0-2]/, /\d/, ":", /[0-5]/, /\d/, "-", /[0-2]/, /\d/, ":", /[0-5]/, /\d/];
            for (var i = 0; i < 5; i++) {
                var a = i * 6;
                if (rawValue.length > a + 1 && rawValue[a] == "2") {
                    rval[a + 1] = /[0-3]/;
                }
            }
            return rval;
        },
        //初始化 获取Options 用于格式化表格
        async initOption() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS6/LIS610",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                });
                this.userOption = res.userOption;
                this.hospOption = res.hospOption;
                this.btnQuery();
            } catch (e) {
                this.$message.warning(e);
            }
        },
        //格式化
        formatFun({ cellValue, column }) {
            return this.commFormatFun(cellValue, column.property);
        },
        //格式化数据
        commFormatFun(cellValue, column) {
            if (column == "hospcode") {
                try {
                    if (cellValue.toLowerCase() == "all" || cellValue == "") {
                        return "全部医院";
                    } else {
                        let hospname = this.hospOption.find((m) => m.data == cellValue);
                        if (hospname != undefined && hospname != null) {
                            return hospname.display;
                        } else {
                            return cellValue;
                        }
                    }
                } catch {}
            } else if (column == "create_user") {
                try {
                    let deptname = this.userOption.find((m) => m.data == cellValue);
                    if (deptname != undefined && deptname != null) {
                        return deptname.display;
                    } else {
                        return cellValue;
                    }
                } catch {}
            } else if (["weekday1", "weekday2", "weekday3", "weekday4", "weekday5", "weekday6", "weekday7"].includes(column)) {
                try {
                    if (cellValue == "1") return "全天采样";
                    else if (cellValue == "0") return "禁止采样";
                    else return cellValue;
                } catch {}
            } else {
                return cellValue;
            }
        },
        //转换为日期区间格式
        transType(value) {
            var showvalue = value.substring(0, 2) + ":" + value.substring(2, 4) + "-" + value.substring(4, 6) + ":" + value.substring(6, 8);
            if (value.length > 8) {
                showvalue += "," + value.substring(8, 10) + ":" + value.substring(10, 12) + "-" + value.substring(12, 14) + ":" + value.substring(14, 16);
                if (value.length > 16) {
                    showvalue += "," + value.substring(16, 18) + ":" + value.substring(18, 20) + "-" + value.substring(20, 22) + ":" + value.substring(22, 24) + value.substring(99, 102);
                }
            }
            return showvalue;
            // }
        },
        //----------------- class -----------------//
        //左侧主表 class
        lRowClassName({ row, rowIndex }) {
            if (this.AddData.indexOf(row.collectdictid) > -1) {
                return "row-new";
            }
            if (this.ModData.indexOf(row.collectdictid) > -1) {
                return "row-modify";
            }
        },
        //右侧子表 class
        rRowClassName({ row, rowIndex }) {
            if (this.$refs.rXTable.hasRowInsert(row)) {
                return "row-new";
            }
            if (this.$refs.rXTable.hasRowChange(row)) {
                return "row-modify";
            }
        },
        rCellClassName({ column, row }) {
            // if (column.property == "collectdictid") {
            //     return "col-readonly";
            // }
        },
    },
};
</script>

<style scoped>
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
table td {
    white-space: nowrap;
}
.top-title {
    margin: 0 3px 0 20px;
    font-size: 12px;
}
.top-button {
    right: 5px;
    position: absolute;
    top: 5px;
    display: flex;
    align-items: center;
}
.pagetop {
    width: 100%;
    height: 35px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}
.pagecenter {
    position: absolute;
    top: 40px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}
.detailxTable {
}
.detail-operation {
    display: flex;
    padding: 0px 2px 0px 5px;
    margin: 5px 0;
}
::v-deep .el-textarea__inner {
    display: block;
    resize: vertical;
    padding: 2px 4px;
}
::v-deep .el-button.is-disabled {
    border: 0px;
    color: grey;
    background-color: #e6e6e6;
    font-weight: normal;
}
::v-deep tr.vxe-body--row.row-modify {
    color: blue;
}
::v-deep tr.vxe-body--row.row-new {
    color: #cc6600;
}
::v-deep .col-readonly {
    background-color: #eeeeee;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #000000;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
.tableStyle tr td {
    padding: 0px 2px 0px 2px;
}
::v-deep .vxe-table--header .vxe-header--column {
    border-right: 1px solid #cccccc;
    border-bottom: 1px solid #ccc;
}
</style>
